package com.ruoyi.xiche.mapper;

import com.ruoyi.xiche.domain.Order;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.xiche.domain.OrderDetailDTO;
import com.ruoyi.xiche.domain.ServiceReview;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author wangruoyang
* @description 针对表【order(订单表)】的数据库操作Mapper
* @createDate 2025-03-17 16:56:26
* @Entity com.ruoyi.xiche.domain.Order
*/
@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    @Select("SELECT o.*, s.*, sr.* " +
            "FROM `order` o " +
            "LEFT JOIN store s ON o.store_id = s.store_id " +
            "LEFT JOIN service_review sr ON o.order_id = sr.order_id")
    @Results({
            @Result(property = "order.orderId", column = "order_id"),
            @Result(property = "order.orderStatus", column = "order_status"),
            @Result(property = "order.verificationCode", column = "verification_code"),
            @Result(property = "order.storeId", column = "store_id"),
            @Result(property = "order.orderTime", column = "order_time"),

            @Result(property = "store.storeId", column = "store_id"),
            @Result(property = "store.storeName", column = "store_name"),

            @Result(property = "serviceReview.reviewId", column = "review_id"),
            @Result(property = "serviceReview.reviewTime", column = "review_time"),
            @Result(property = "serviceReview.content", column = "content")
    })
    List<OrderDetailDTO> getOrderDetails();

    @Select("SELECT sr.review_id, sr.review_time, sr.content, sr.images, sr.rating, sr.member_id, sr.order_id, sr.ext1, sr.ext2, sr.ext3, sr.ext4, sr.ext5 " +
            "FROM `order` o " +
            "LEFT JOIN store s ON o.store_id = s.store_id " +
            "LEFT JOIN service_review sr ON o.order_id = sr.order_id " +
            "WHERE s.store_id = #{storeId}")
    @Results({
            @Result(property = "serviceReview.reviewId", column = "review_id"),
            @Result(property = "serviceReview.reviewTime", column = "review_time"),
            @Result(property = "serviceReview.content", column = "content"),
            @Result(property = "serviceReview.images", column = "images"),
            @Result(property = "serviceReview.rating", column = "rating"),
            @Result(property = "serviceReview.memberId", column = "member_id"),
            @Result(property = "serviceReview.orderId", column = "order_id"),
            @Result(property = "serviceReview.ext1", column = "ext1"),
            @Result(property = "serviceReview.ext2", column = "ext2"),
            @Result(property = "serviceReview.ext3", column = "ext3"),
            @Result(property = "serviceReview.ext4", column = "ext4"),
            @Result(property = "serviceReview.ext5", column = "ext5")
    })
    List<OrderDetailDTO> getOrderDetailsByStoreId(@Param("storeId") int storeId);
}




